package org.halk.redis.lock.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 *
 * @Author halk
 * @Date 2021/12/24 15:23
 * @desc
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(CustomException.class)
    public String customException(CustomException e) {
        log.error(e.getMessage(), e.getHttpStatus(), e);
        return e.getMessage();
    }

    @ExceptionHandler(Exception.class)
    public String handleException(Exception e) {
        log.error(e.getMessage(), e);
        return e.getMessage();
    }
}
